package vashion.azeroth.back.core.context;

import org.springframework.stereotype.Service;
import vashion.azeroth.core.personal.pojo.PersonalMember;

import javax.servlet.http.HttpServletRequest;

@Service
public class BackUserContext {
	
	public static final String LOGIN_USER = "loginUser";

    public void setLoginUser(PersonalMember user, HttpServletRequest request) {
        request.getSession().setAttribute(LOGIN_USER, user);
    }

    public PersonalMember getLoginUser(HttpServletRequest request) {
        return (PersonalMember) request.getSession().getAttribute(LOGIN_USER);
    }


    public void removeLoginUser(HttpServletRequest request) {
        request.getSession().removeAttribute(LOGIN_USER);
    }

    public String getUserName(HttpServletRequest request) {
    	return getLoginUser(request).getMemberName();
    }
}
